<?php

/*
 * File  : users.php
 * Table : userss
 */
//session_start();
//cek session

if ((!$_SESSION["USRID"] AND !$_SESSION["USRPASS"]) OR $_SESSION["USRLEVEL"] != "admin") {
    header("location: ../index.php");
    exit();
}
//end
?>

<?php

//include "../../../library/fungsi.lib.php";
$aksi = "cms/bab/m_users/aksi_users.php";
//$folder_location = URLHOST . "cms/bab/m_mber/";

switch ($_GET["opr"]) {

    // tampil users
    default :
        echo "<h2>User</h2>";
        echo '<input type="button" value="Tambah User" onclick="window.location.href=\'?module=users&opr=tambah\';" />';

        echo "<table>";
        echo "<tr><th>No</th><th>Username</th><th>Nama Lengkap</th><th>Level</th><th>Aksi</th></tr>";
        $tampil = mysql_query("SELECT user_id, user_name, user_level FROM users ORDER BY user_id ASC");
        $no = 1;
        while ($row = mysql_fetch_array($tampil)) {

            echo "<tr>";
            echo "<td>$no</td>";
            echo "<td>" . $row["user_id"] . "</td>";
            echo "<td>" . $row["user_name"] . "</td>";
            echo "<td>" . $row["user_level"] . "</td>";
            echo "<td><a href=?module=users&opr=edit&id=" . $row["user_id"] . ">Edit</a> | 
	               <a href=" . URLHOST . "$aksi?module=users&opr=hapus&id=" . $row["user_id"] . "  onClick=\"return confirm('Hapus Member " . $row["user_name"] . "?')\">Hapus</a></td>";
            echo "</tr>";
            $no++;
        }
        echo "</table>";
        break;

    case "tambah":
        echo "<script language=\"javascript\" type=\"text/javascript\" src=\"bab/m_users/ajax.js\"></script>";
        echo "<h2>Tambah Member</h2>";
        echo "<form method=POST action=" . URLHOST . "$aksi?module=users&opr=input>";
        echo "<table>";
        echo "<tr><td>Username</td><td><input type=text name='in_user_id' id='in_user_id' onblur=\"Checker()\" /><span id=\"imgTry\">&nbsp;</span></td></tr>";
        echo "<tr><td>Password</td><td><input type=password name='in_user_pass' /></td></tr>";
        echo "<tr><td>Nama Lengkap</td><td><input type=text name='in_user_name' /></td></tr>";
        echo "<tr><td>Email</td><td><input type=text name='in_user_mail' /></td></tr>";
        echo "<tr><td>Telp</td><td><input type=text name='in_user_telp' />";
        echo "<tr><td>Hak Akses</td><td><select name='in_user_level'>
                                            <option value='0'>-- Pilih --</option>
                                            <option value='users'>Member</option>
                                            <option value='admin'>Administrator</option>
                                        </select></td></tr>";
        echo "<tr><td colspan=2><input type=submit value=Simpan>
                <input type=button value=Batal onclick=self.history.back()></td></tr>";
        echo "</table>";
        echo "</form>";
        break;

    case "edit":
        $id = $_GET["id"];
        $sql = mysql_query("SELECT * FROM users WHERE user_id='$id'");
        $f = mysql_fetch_array($sql);

        echo "<h2>Edit Member</h2>";
        echo "<form method=POST action=" . URLHOST . "$aksi?module=users&opr=update>";
        echo "<input type=hidden name=id value='" . $f["user_id"] . "'>";
        echo "<table>";
        echo "<tr><td>Username</td><td><input type=text name='in_user_id' value='" . $f["user_id"] . "' readonly /></td></tr>";
        echo "<tr><td>Password</td><td><input type=password name='in_user_pass' /></td></tr>";
        echo "<tr><td>Nama Lengkap</td><td><input type=text name='in_user_name' value='" . $f["user_name"] . "' /></td></tr>";
        echo "<tr><td>Email</td><td><input type=text name='in_user_mail' value='" . $f["user_mail"] . "' /></td></tr>";
        echo "<tr><td>Telp</td><td><input type=text name='in_user_telp' value='" . $f["user_telp"] . "' />";
        echo "<tr><td>Hak Akses</td><td><select name='in_user_level'>";
        echo user_level_option($f["user_level"]);
        echo "
                                            <option value='users'>Member</option>
                                            <option value='admin'>Administrator</option>
                                        </select></td></tr>";
        echo "<tr><td>Status</td><td>";
        echo "  <select name='in_mbr_status' id='in_mbr_status'>";
        echo  status_option($f["user_status"]);
        echo "      <option value='Y'>Aktif</option>";
        echo "      <option value='N'>Tidak Aktif</option>";
        echo "  </select>";
        echo "</td></tr>";
        echo "<tr><td colspan=2><input type=submit value=Simpan><input type=button value=Batal onclick=self.history.back()></td></tr>";
        echo "</table>";
        echo "</form>";
        break;
}
?>
